var t = require("../../../@babel/runtime/helpers/defineProperty"), a = require("../../../mybehaviors/location/location"), e = getApp();

Component({
    behaviors: [ a ],
    properties: {
        datas: {
            type: null
        },
        component_id: {
            type: null
        },
        bottomShowBol: {
            type: null
        },
        bottomShowBolIndex: {
            type: null
        },
        index: {
            type: null
        },
        btnFlag: {
            type: null
        }
    },
    data: {
        emptyImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png",
        clientWidth: "375",
        active: "3",
        titleName: [ {
            id: "popularity_short",
            text: "人气商家",
            url: "plugin.store-cashier.frontend.store.store.get-store-list-rank"
        }, {
            id: "new_short",
            text: "新入驻商家",
            url: "plugin.store-cashier.frontend.store.store.get-store-list-rank"
        }, {
            id: "preferential_short",
            text: "优惠商家",
            url: "plugin.store-cashier.frontend.store.store.get-store-list-rank"
        }, {
            id: "nearby",
            text: "附近商家",
            url: "plugin.store-cashier.frontend.store.store.get-store-list-rank"
        } ],
        api: "",
        dataJson: {},
        shopList0: [],
        isLoadMore0: !1,
        page0: 1,
        total_page0: 0,
        shopList1: [],
        isLoadMore1: !1,
        page1: 1,
        total_page1: 0,
        shopList2: [],
        isLoadMore2: !1,
        page2: 1,
        total_page2: 0,
        shopList3: [],
        isLoadMore3: !1,
        page3: 1,
        total_page3: 0
    },
    lifetimes: {
        attached: function() {
            var t = wx.getStorageSync("langIndex");
            this.setData({
                language: t.en
            });
        },
        moved: function() {},
        detached: function() {}
    },
    attached: function() {},
    ready: function() {
        var t = this;
        this.data.datas.discount_list.indexOf("1") > -1 ? this.setData({
            showMun: !0
        }) : this.data.datas.discount_list.indexOf("1") < 0 && this.setData({
            showMun: !1
        }), this.setData({
            clientWidth: wx.getSystemInfoSync().windowWidth
        }), this._getLocation(function() {
            t.data.datas.tab_list.indexOf("4") > -1 ? (t.chooseTab(" ", "nearby"), t.setData({
                active: "3"
            })) : t.data.datas.tab_list.indexOf("1") > -1 ? (t.chooseTab(" ", "popularity_short"), 
            t.setData({
                active: "0"
            })) : t.data.datas.tab_list.indexOf("2") > -1 ? (t.chooseTab(" ", "new_short"), 
            t.setData({
                active: "1"
            })) : t.data.datas.tab_list.indexOf("3") > -1 && (t.chooseTab(" ", "preferential_short"), 
            t.setData({
                active: "2"
            }));
        });
    },
    pageLifetimes: {
        show: function() {},
        hide: function() {},
        resize: function() {}
    },
    methods: {
        toRouter: function(t) {
            var a = t.currentTarget.dataset.item;
            1 == a.specify_show ? wx.navigateTo({
                url: "/packageC/o2o/o2oStore/o2oStore?store_id=" + a.id + "&fromHome=1"
            }) : 1 == a.store_decorate ? wx.navigateTo({
                url: "/packageG/o2o/HomeSeller/HomeSeller?store_id=" + a.id
            }) : wx.navigateTo({
                url: "/packageC/o2o/HomeSeller/HomeSeller?store_id=" + a.id
            });
        },
        goToAdress: function(t) {
            var a = t.currentTarget.dataset.items.latitude, s = t.currentTarget.dataset.items.longitude, o = t.currentTarget.dataset.items.store_name, i = e.BMapTransqqMap(parseFloat(s), parseFloat(a));
            wx.openLocation({
                latitude: i.lat,
                longitude: i.lng,
                scale: 18,
                name: o
            });
        },
        onClick: function(t) {
            "人气商家" == t.detail.title ? (this.setData({
                active: 0
            }), this.chooseTab("", "popularity_short")) : "新入驻商家" == t.detail.title ? (this.setData({
                active: 1
            }), this.chooseTab("", "new_short")) : "优惠商家" == t.detail.title ? (this.setData({
                active: 2
            }), this.chooseTab("", "preferential_short")) : "附近商家" == t.detail.title && (this.setData({
                active: 3
            }), this.chooseTab("", "nearby"));
        },
        chooseTab: function(a, s) {
            var o;
            this.setData({
                tab: this.data.titleName.findIndex(function(t) {
                    return t.id == s;
                })
            }), this.setData({
                api: this.data.titleName[this.data.tab].url
            });
            var i = this.data.titleName[this.data.tab].id;
            "preferential_short" == i && (i = "1" == this.data.datas.discount_type ? "preferential_short_percentage" : "preferential_short"), 
            this.setData((t(o = {}, "isLoadMore".concat(this.data.tab), !1), t(o, "total_page".concat(this.data.tab), 0), 
            t(o, "page".concat(this.data.tab), 1), o));
            var n = e.qqMapTransBMap(parseFloat(this.data.point.lng), parseFloat(this.data.point.lat));
            this.setData({
                dataJson: {
                    lng: n.lng ? n.lng : "",
                    lat: n.lat ? n.lat : "",
                    city_name: this.data.city,
                    page: this.data["page".concat(this.data.tab)],
                    sorting: i,
                    is_aggregation: 1
                }
            });
            var d = [];
            this.data.datas.list && this.data.datas.list.length > 0 && (this.data.datas.list.forEach(function(t) {
                d.push(t.id);
            }), this.data.dataJson.category_ids = d), this.getList();
        },
        getList: function() {
            var a = this, s = e.getNetAddresss(a.data.api);
            e._postNetWork({
                url: s,
                data: this.data.dataJson,
                success: function(e) {
                    var s, o, i = e.data;
                    1 == i.result ? (a.setData((t(s = {}, "shopList".concat(a.data.tab), i.data.data), 
                    t(s, "total_page".concat(a.data.tab), i.data.last_page), s)), a.data["total_page".concat(a.data.tab)] <= 1 ? a.setData(t({}, "isLoadMore".concat(a.data.tab), !1)) : a.setData(t({}, "isLoadMore".concat(a.data.tab), !0)), 
                    a.data["shopList".concat(a.data.tab)].length > a.data.datas.get_number && (a.data["shopList".concat(a.data.tab)].splice(a.data.datas.get_number, a.data["shopList".concat(a.data.tab)].length - a.data.datas.get_number), 
                    a.setData((t(o = {}, "shopList".concat(a.data.tab), i.data.data), t(o, "isLoadMore".concat(a.data.tab), !1), 
                    o)))) : console.log(i.msg);
                },
                fail: function(t) {
                    console.log(t), wx.showToast({
                        title: t.msg,
                        duration: 1e3,
                        icon: "none"
                    });
                }
            });
        },
        getMoreList: function() {
            var a, s = this;
            if (this.setData(t({}, "isLoadMore".concat(this.data.tab), !1)), !(this.data["page".concat(this.data.tab)] >= this.data["total_page".concat(this.data.tab)])) {
                this.data["page".concat(this.data.tab)] = this.data["page".concat(this.data.tab)] + 1, 
                a = e.qqMapTransBMap(parseFloat(this.data.point.lng), parseFloat(this.data.point.lat));
                var o = this.data.titleName[this.data.tab].id;
                "preferential_short" == o && (o = "1" == this.data.datas.discount_type ? "preferential_short_percentage" : "preferential_short"), 
                this.setData({
                    dataJson: {
                        lng: a.lng ? a.lng : "",
                        lat: a.lat ? a.lat : "",
                        city_name: this.data.city,
                        page: this.data["page".concat(this.data.tab)],
                        sorting: o,
                        is_aggregation: 1
                    }
                });
                var i = [];
                this.data.datas.list && this.data.datas.list.length > 0 && (this.data.datas.list.forEach(function(t) {
                    i.push(t.id);
                }), this.data.dataJson.category_ids = i);
                var n = e.getNetAddresss(s.data.api);
                e._postNetWork({
                    url: n,
                    data: s.data.dataJson,
                    success: function(a) {
                        var e, o, i, n = a.data;
                        1 == n.result ? (s.setData((t(e = {}, "shopList".concat(s.data.tab), s.data["shopList".concat(s.data.tab)].concat(n.data.data)), 
                        t(e, "total_page".concat(s.data.tab), n.data.last_page), e)), s.data["page".concat(s.data.tab)] >= s.data["total_page".concat(s.data.tab)] ? s.setData(t({}, "isLoadMore".concat(s.data.tab), !1)) : s.setData(t({}, "isLoadMore".concat(s.data.tab), !0)), 
                        s.data["shopList".concat(s.data.tab)].length > s.data.datas.get_number && (s.data["shopList".concat(s.data.tab)].splice(s.data.datas.get_number, s.data["shopList".concat(s.data.tab)].length - s.data.datas.get_number), 
                        s.setData((t(o = {}, "shopList".concat(s.data.tab), s.data["shopList".concat(s.data.tab)]), 
                        t(o, "isLoadMore".concat(s.data.tab), !1), o)))) : s.setData((t(i = {}, "page".concat(s.data.tab), [ "page".concat(s.data.tab) ] - 1), 
                        t(i, "isLoadMore".concat(s.data.tab), !1), i));
                    },
                    fail: function(t) {
                        console.log(t);
                    }
                });
            }
        }
    },
    observers: {
        bottomShowBol: function(t) {
            t && this.data.bottomShowBolIndex == this.data.index && this.data["isLoadMore".concat(this.data.tab)] && this.getMoreList();
        }
    }
});